<template>
  <div class="app-container flex-col minH">
    <div class="topline w100p bgwhite pt20 pb10 radius10 pl10 pr20 justify-between">
      <div>
        <el-input v-model="uid" style="width: 280px" placeholder="搜尋用戶ID..." :prefix-icon="Search" class="search mr10 mb10" />
        <el-input v-model="realname" style="width: 280px" placeholder="搜尋真實姓名..." :prefix-icon="Search" class="search mr10 mb10" />
        <el-input v-model="id_card" style="width: 280px" placeholder="搜尋身份證號..." :prefix-icon="Search" class="search mr10 mb10" />

      </div>
      <div class="noshrink mb10">
        <el-button class="btn2" @click="search()">查詢</el-button>
        <el-button class="btn1" @click="reset()">重置</el-button>
      </div>
    </div>
    <div class="mt15 radius10 hidden pb15 flex1 bgwhite  flex-col w100p">
      <div class="flex1 w100p ">
        <el-table :data="tableData" style="width: 100%" cell-class-name="tbcell" header-cell-class-name="hdcell">
          <el-table-column prop="uid" label="用戶訊息" width="150">
            <template #default="scope">
              <span @click="showUser(scope.row.uid)">ID:{{ scope.row.uid }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="realname" label="真實姓名" width="100" />
          <el-table-column prop="id_card" label="身份證號" width="200" />
          <el-table-column prop="mobile" label="手機號" width="150" />

          <el-table-column prop="front_view" label="證件照正面" width="150">
            <template #default="scope">
              <el-avatar shape="square" :size="50" :fit="'cover'" :src="scope.row.front_view" />
            </template>
          </el-table-column>
          <el-table-column prop="back_view" label="證件照反面" width="150">
            <template #default="scope">
              <el-avatar shape="square" :size="50" :fit="'cover'" :src="scope.row.back_view" />
            </template>
          </el-table-column>
          <el-table-column prop="hand_view" label="手持身份証照片" width="200">
            <template #default="scope">
              <el-avatar shape="square" :size="50" :fit="'cover'" :src="scope.row.hand_view" />
            </template>
          </el-table-column>
          <el-table-column prop="" label="審核狀態" width="100">
            <template #default="scope">
              <div class="yellow" v-if="scope.row.state != 2 && scope.row.state != 1">審核中</div>
              <div class="blue" v-if="scope.row.state == 1">通過</div>
              <div class="red" v-if="scope.row.state == 2">拒絕</div>
            </template>
          </el-table-column>
          <el-table-column prop="examine_name" label="審核人" width="100" />
          <el-table-column prop="fail_reason" label="拒絕原因" width="150" />
          <el-table-column prop="created_at" label="創建時間" width="200" />
          <el-table-column prop="" label="操作" width="100" fixed="right">
            <template #default="scope">
              <div class=" pointer" @click="edit(scope.row)">編輯</div>

            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="plr20 mlauto mt20">
        <el-pagination v-model:current-page="currentPage" prev-text="上一頁" next-text="下一頁" :default-page-size="15" :small="small" :disabled="disabled" :background="true" layout="prev, pager, next, jumper" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
      </div>

    </div>
  </div>
</template>

<script setup>
import { Search } from '@element-plus/icons-vue'
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router';
import { realnameList } from '@/api/usersManage'
import { inject } from 'vue';
const showUser = inject('showUser');
onMounted(() => {
  getRealnameList()
})
const getRealnameList = () => {
  realnameList({
    page: currentPage.value,
    uid: uid.value,
    realname: realname.value,
    id_card: id_card.value
  }).then((res) => {
    console.log('实名认证列表', res)
    tableData.value = res.data.data
    total.value = res.data.total
  })
}

const uid = ref('')
const realname = ref('')
const id_card = ref('')
const dialogTableVisible = ref(false)
const tableData = ref([])
const currentPage = ref(1)
const total = ref(0)
const handleSizeChange = (val) => {
  console.log(`${val} items per page`)
}
const handleCurrentChange = (val) => {
  console.log(`current page: ${val}`)
}
// 搜尋
const search = () => {
  getRealnameList()
}
// 重置
const reset = () => {
  uid.value = ''
  realname.value = ''
  id_card.value = ''
  getRealnameList()

}
const router = useRouter()
const edit = (row) => {
  router.push({ path: 'editRealname', query: row })
}
</script>

<style lang="scss" scoped>
.search {
  overflow: hidden;
  border-radius: 10px !important;
  // padding: 5px 0px;
}

:deep(.el-input__wrapper) {
  box-shadow: none;
}
</style>
<style></style>
 